//
//  AYMUserHeaderView.m
//  ky
//
//  Created by guo3920591 on 16/5/5.
//  Copyright © 2016年 guo3920591. All rights reserved.
//

#import "AYMUserHeaderView.h"
#import "AYMPersonalMSGController.h"


@implementation AYMUserHeaderView

-(instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}


#pragma mark - 布局界面
-(void)setupUI{
    
    self.backgroundColor = LeftHeadViewColor;
    UserData *userData = [UserData sharedInstance];
    [userData loadUserInfoFromSanBox];
    
    UIImageView *iconImage = [[UIImageView alloc]init];
     [iconImage sd_setImageWithURL:[NSURL URLWithString:userData.head_photo] placeholderImage:[UIImage imageNamed:@"name"]];
    UILabel *nameLabel = [UILabel textColor:[UIColor whiteColor] font:leftViewLoginFont];
    self.nameLabel = nameLabel;
    
    UILabel *msgLabel = [UILabel textColor:[UIColor whiteColor] font:leftViewLoginFont];
    self.msgLabel = msgLabel;
    [self addSubview:iconImage];
    [self addSubview:nameLabel];
    [self addSubview:msgLabel];
    
    [iconImage makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.leading.equalTo(20);
        make.height.width.equalTo(50);
    }];
    
    [nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(iconImage.trailing).offset(10);
        make.top.equalTo(iconImage);
    }];
    
    [msgLabel makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(nameLabel);
        make.bottom.equalTo(iconImage);
    }];
}

#pragma mark - 触摸跳转至个人信息界面
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    if ([self.delegate respondsToSelector:@selector(userHeaderView:)]) {
        [self.delegate userHeaderView:self];
    }
}

-(void)updateView{

    UserData *userData = [UserData sharedInstance];
    [userData loadUserInfoFromSanBox];
    self.msgLabel.text = @"基本资料信息";
    self.nameLabel.text = userData.true_name;

}


@end
